﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using WebComponents.Data;
using WebComponents;

public partial class Module_LatestNews : System.Web.UI.UserControl {
  private int _itemCount = 6;

  public int ItemCount {
    get { return _itemCount; }
    set { _itemCount = value; }
  }

  protected void Page_Load(object sender, EventArgs e) {
    var list = ArticleController.GetByCateID(78, Global.CurrentCultureCode).Where(a => a.IsApproved == true).Skip(0).Take(ItemCount).ToList();
    rptArticle.DataSource = list;
    rptArticle.DataBind();
  }
  protected void rptArticle_ItemDataBound(object sender, RepeaterItemEventArgs e) {
    ArticleInfo article = e.Item.DataItem as ArticleInfo;
    if (article != null) {
      if (article.ImageUrl != "") {
        (e.Item.FindControl("lblImage") as Literal).Text = string.Format("<a href=\"{4}chi-tiet-tin/{0}/{3}.gbit\" class=\"link_pic_icon_news\"><img src=\"{4}{1}\"  width=\"59\" height=\"57\" alt=\"{2}\" class=\"pic_border\"/></a>", article.ArticleID, article.ImageUrl, article.Title, ConvertType.StripDiacritics(article.Title), Page.ResolveClientUrl("~/"));
      } else
        (e.Item.FindControl("lblImage") as Literal).Visible = false;
    }
  }
  public string Get70KyTu(object obj) {
    string str = ConvertType.ToString(obj);
    if (str.Length > 70)
      return str.Substring(0, 70) + "...";
    return str;
  }
}
